package com.gxa.logistics.service.impl;

import com.github.pagehelper.PageHelper;
import com.gxa.logistics.common.base.PageWrapperDTO;
import com.gxa.logistics.common.base.RespResult;
import com.gxa.logistics.common.util.PageResultUtil;
import com.gxa.logistics.domain.dto.*;
import com.gxa.logistics.domain.vo.VehicleVO;
import com.gxa.logistics.mapper.VehicleMapper;
import com.gxa.logistics.service.VehicleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class VehicleServiceImpl implements VehicleService {
    @Autowired
    private VehicleMapper vehicleMapper;

    @Override
    public RespResult<PageWrapperDTO<VehicleVO>> list(VehicleReqListDTO vehicleReqListDTO) {
        // 使用分页插件
        PageHelper.startPage(vehicleReqListDTO.getPageNo(), vehicleReqListDTO.getPageSize());
        // 包装的分页返回对象
        PageWrapperDTO<VehicleVO> pageCommon = new PageWrapperDTO<>();
        List<VehicleVO> vehicleList = vehicleMapper.findVehicleByWhere(vehicleReqListDTO);
        // 设置分页返回对象
        PageResultUtil.setPageResult(vehicleList,pageCommon);
        return RespResult.success(pageCommon);
    }

    @Override
    public void insertVehicle(VehicleSaveDTO vehicleSaveDTO) {
        vehicleMapper.insertVehicle(vehicleSaveDTO);
    }

    @Override
    public void updateVehicle(VehicleUpdateDTO vehicleUpdateDTO) {
        vehicleMapper.updateVehicle(vehicleUpdateDTO);
    }

    @Override
    public void delVehicleBylpnum(String lpnum) {
        vehicleMapper.delVehicleBylpnum(lpnum);
    }
}


